#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t;
struct A
{
    int d,v,a;
}car[100010];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        ll n,m,l,ve;
        cin>>n>>m>>l>>ve;
        ll p[100010];
        bool flag=1;
        for(int i=1;i<=n;i++)
        {
            cin>>car[i].d>>car[i].v>>car[i].a;
            if(car[i].a)
            {
                flag=0;
            }
        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
        }
        sort(p+1,p+m+1);
        if(flag)
        {
            ll ans=0;
            for(int i=1;i<=n;i++)
            {
                if(car[i].v>ve)
                {
                    ll pos=lower_bound(p+1,p+m+1,car[i].d)-p;
                    if(pos==m+1)
                    {
                        continue;
                    }
                    ans++;
                }
            }
            if(ans==0)
            {
                cout<<"0 "<<m<<"\n";
                continue;
            }
            cout<<ans<<" "<<m-1<<"\n";
        }
    }
    return 0;
}
